package com.UnionPayCenter.operation.manager.impl;

import com.UnionPayCenter.mapper.ActivityTypeMapper;
import com.UnionPayCenter.operation.entity.ActivityType;
import com.UnionPayCenter.operation.manager.ActivityTypeManager;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class ActivityTypeManagerImpl implements ActivityTypeManager {

    @Autowired
    private ActivityTypeMapper activityTypeMapper;

    @Override
    public List<ActivityType> getAll() {
        return activityTypeMapper.selectByCondition(null);
    }

    @Override
    public ActivityType getByType(Integer operationType) {
        ActivityType activityType = new ActivityType();
        activityType.setOperationType(operationType);
        List<ActivityType> activityTypes = activityTypeMapper.selectByCondition(activityType);
        if (CollectionUtils.isEmpty(activityTypes)) {
            log.warn("activity type not exist, operationType {}", operationType);
            return null;
        }
        if (activityTypes.size() > 1) {
            log.warn("activity type duplicated, operationType {}", operationType);
        }
        return activityTypes.get(0);
    }

    @Override
    public ActivityType getById(Integer activityTypeId) {
        return activityTypeMapper.selectByPrimaryKey(activityTypeId);
    }
}
